﻿using System;
using System.Web;
using System.Web.Caching;
using Actya.Core.Infrastructure;

namespace Actya.Web.Infrastructure
{
	public class WebCache : ICache
	{
		protected Cache InnerCache
		{
			get
			{
				if (HttpContext.Current == null)
				{
					throw new InvalidOperationException("The WebCache class only works within an HTTP context.");
				}
				return HttpContext.Current.Cache;
			}
		}
		public void Add(string cacheKey, object objectToCache, TimeSpan cacheDuration)
		{
			this.InnerCache.Add(cacheKey, objectToCache, null, DateTime.MaxValue, cacheDuration, CacheItemPriority.Normal, null);
		}

		public object Get(string cacheKey)
		{
			return this.InnerCache.Get(cacheKey);
		}

		public void Remove(string cacheKey)
		{
			this.InnerCache.Remove(cacheKey);
		}
	}
}
